package com.ctgu.chatapp.utils

import android.view.View
import androidx.lifecycle.MutableLiveData
import androidx.navigation.findNavController
import com.ctgu.chatapp.R
import com.ctgu.chatapp.model.Retrofit.Pojo.Friend
import com.ctgu.chatapp.showPojo.Contact
import com.ctgu.chatapp.showPojo.ItemFriend
import com.ctgu.chatapp.view.FriendChatDirections
import net.sourceforge.pinyin4j.PinyinHelper

class Utils {

    companion object {

        var chatID: Long = 0

        var friendID: Long = 0

        var FriendList = listOf<Friend>()

        @JvmStatic
        fun isEmpty(s: MutableLiveData<String>): Boolean {
            return s.value.isNullOrEmpty()
        }

        @JvmStatic
        fun clearInformation(s: MutableLiveData<String>) {
            s.value = ""
        }

        @JvmStatic
        fun toChat(view: View, contact: Contact, chatID: Long, profile: String) {
            val action = FriendChatDirections.actionGlobalFriendChat(
                chatID = chatID,
                profile = profile,
                friend = ItemFriend(contact.profile, contact.chatID, contact.nickName)
            )
            friendID = contact.chatID
            view.findNavController().navigate(action)
        }

        @JvmStatic
        fun chineseToPinyin(name: String): String {
            val str = PinyinHelper.toHanyuPinyinStringArray(name.toCharArray()[0])
            return if (str != null) str[0][0].uppercaseChar().toString()
            else name.first().toString()
        }

        @JvmStatic
        fun toSearch(view: View) {
            view.findNavController().navigate(R.id.action_global_search)
        }
    }
}